<?php
apf_require_class("Solr_Dao_Base");
class Solr_Dao_ReportHost extends Solr_Dao_Base{

    public function insert_report_host($params) {
        $pdo = $this->get_srm_pdo();
        $sql = "replace into report_host set hostname_id=?,port=?,datei=?,count_min=?,slow_min=?,max_count_min=?";
        $stmt = $pdo->prepare($sql);
        $stmt->execute(array($params['hostname_id'],$params['port'],$params['datei'],
        $params['count_min'],$params['slow_min'],$params['max_count_min']));
        return $stmt->rowCount();
    }

    public function get_host_reports_list($params,$page,$limit=20){
        $pdo = $this->get_srs_pdo();
        $offset=($page-1)*$limit;
        $where='';
        if($params['hostname_id'])$where.=" and hostname_id='".$params['hostname_id']."' ";
        if($params['datei'])$where.=" and datei='".$params['datei']."' ";
        if($params['port'])$where.=" and port='".$params['port']."' ";
        $sql="select * from report_host where 1 ".$where." order by datei desc limit $offset,$limit";
        $stmt = $pdo->prepare($sql);
        $stmt->execute();
        return $stmt->fetchAll();
    }

    public function get_host_reports_count($params){
        $pdo = $this->get_srs_pdo();
        $where='';
        if($params['hostname_id'])$where.=" and hostname_id='".$params['hostname_id']."' ";
        if($params['datei'])$where.=" and datei='".$params['datei']."' ";
        if($params['port'])$where.=" and port='".$params['port']."' ";
        $sql="select count('x') from report_host where 1 ".$where;
        $stmt = $pdo->prepare($sql);
        $stmt->execute();
        return $stmt->fetchColumn();
    }

}